/*
 * @Author: Jiraiya
 * @Date: 2020-06-12 15:53:17
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-06-12 19:22:59
 * @Description: 
 */ 
class TreeNode{
    constructor(val){
        this.val = val;
        this.left = this.right = null;
    }
}

const treeByArr = function(arr){
    if(!arr.length) return;
    const root = new TreeNode(arr.shift());
    const queue = [root];
    while(queue.length){
        const node = queue.shift();
        const leftVal = arr.shift();
        if(leftVal){
            node.left = new TreeNode(leftVal);
            queue.push(node.left);
        }

        const rightVal = arr.shift();
        if(rightVal){
            node.right = new TreeNode(rightVal);
            queue.push(node.right);
        }
    }
    return root;
}

module.exports = {
    treeByArr,
}